Skip to content

chore(sdk): [NET-1462] StreamrClient#searchStreams() queries using Stream entity #3132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 25, 2025

Conversation

teogeb
Copy link
Contributor

@teogeb teogeb commented May 23, 2025

Changed the StreamrClient#searchStreams() to use Stream entity directly. The previous implementation used the StreamPermission entity, which made the queries more complex and slower. See benchmarks below.

This also fixes a potential bug as the previous implementation relied on the contents of StreamPermission#id to be prefixed with stream id. Most or all of the IDs in our subgraphs have used that kind of id format, but it is not a documented feature of the subgraphs.

Benchmarks

The benchmarks were run in dev2 environment which had ~10000 streams

Test Before After Speed reduction
query all streams ~2700ms ~480ms ~80%
search one stream which matches a search term ~44ms ~34ms ~25%
search permissions for user ~72ms ~50ms ~30%
search permissions for user, allowing public permission ~200ms ~100ms ~50%

Related changes

Removed obsolete createWhereClause() method from TheGraphClient.

Copy link

linear bot commented May 23, 2025

@github-actions github-actions bot added the utils label May 23, 2025
@teogeb teogeb changed the title fix(sdk): StreamrClient#searchStreams() queries using Stream entity fix(sdk): [NET-1462] StreamrClient#searchStreams() queries using Stream entity May 23, 2025
teogeb added a commit to streamr-dev/network-contracts that referenced this pull request May 23, 2025
Added new field to `Stream` entity: `Stream#idAsString`. It has same
value as in the `id` field. The field allows us do to substring queries
for the field id (by using `idAsString_contains` where clause).

This feature is needed e.g. in
streamr-dev/network#3132.
@github-actions github-actions bot added the sdk label May 23, 2025
teogeb added a commit that referenced this pull request Jun 5, 2025
…nt#searchStreams()` (#3131)

**This is a breaking changes at this changes the StreamrClient API**

Note that the `id_gt` relies on the fact that `StreamPermission` ids are
prefixed with stream ids in The Graph. We'll change that in a follow-up
PR (#3132).
Base automatically changed from NET-1464 to main June 5, 2025 08:52
teogeb added a commit to streamr-dev/network-contracts that referenced this pull request Jun 17, 2025
Added new field to `Stream` entity: `Stream#idAsString`. It has same
value as in the `id` field. The field allows us to do substring queries
for the field id (by using `idAsString_contains` where clause).

This feature is needed e.g. in
streamr-dev/network#3132.
@github-actions github-actions bot added the docs label Jun 25, 2025
@teogeb teogeb changed the title fix(sdk): [NET-1462] StreamrClient#searchStreams() queries using Stream entity chore(sdk): [NET-1462] StreamrClient#searchStreams() queries using Stream entity Jun 25, 2025
@teogeb teogeb requested a review from Copilot June 25, 2025 11:11
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR optimizes the searchStreams functionality in the SDK by switching the GraphQL queries from using the StreamPermission entity to the Stream entity directly, resulting in simpler queries and significant performance improvements.

  • Refactored query building in searchStreams to use inline where clauses.
  • Updated the SearchStreamsResultItem interface and related transformations in the StreamRegistry.
  • Removed the unused createWhereClause utility in TheGraphClient.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
packages/utils/src/TheGraphClient.ts Removed the obsolete createWhereClause function.
packages/sdk/src/contracts/searchStreams.ts Refactored the query to use the Stream entity directly and updated filter logic.
packages/sdk/src/contracts/StreamRegistry.ts Adjusted response processing to match the new stream query structure.
CHANGELOG.md Updated changelog with a reference to the optimization PR.
Comments suppressed due to low confidence (1)

packages/sdk/src/contracts/searchStreams.ts:16

  • The SearchStreamsResultItem interface still defines a 'permissions' field even though the updated GraphQL query only returns 'id' and 'metadata'. Consider updating or removing the 'permissions' field to reflect the actual response data.
export interface SearchStreamsResultItem {

@teogeb teogeb requested a review from harbu June 25, 2025 11:57
@teogeb teogeb merged commit 3e2a6a6 into main Jun 25, 2025
24 checks passed
@teogeb teogeb deleted the NET-1462 branch June 25, 2025 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants